#!/bin/sh

export VER='1.1.8'
export MAINVER='1.1.8'
export REV=87
export FEATURES='增加对首页右边栏“热门微博”模块的屏蔽；增加对导航栏“发给我的”、“好友圈”的屏蔽；修正“不要屏蔽我自己的微博”功能失效的问题；修正去除主页右边栏后删除微博按钮错位的问题'

while getopts ":nd" optname
do
	case "$optname" in
		"n") COMPRESS=' --nocompress';;
		"d") COMPRESS=' --nocompress'; PARAMS=' --flag=DEBUG';;
		"?") echo "Unknown option -$OPTARG"; exit 1;;
		":") echo "Missing argument value for option -$OPTARG"; exit 1;;
	esac
done

# Greasemonkey
printf 'Building Greasemonkey script...'
export CSS=`./compile.pl $PARAMS --flag=GREASEMONKEY settings.css`
export HTML=`./compile.pl $PARAMS --flag=GREASEMONKEY settings.html`
SCRIPT="release/latest/weiboFilter-v${VER}.user.js"
./compile.pl --nocompress head.js > $SCRIPT
printf '\n' >> $SCRIPT
./compile.pl $COMPRESS $PARAMS --flag=GREASEMONKEY weiboFilter.user.js >> $SCRIPT
unset CSS HTML
echo ' done.'

# Chrome
printf 'Building Chrome extension...'
PACKAGE="release/latest/weiboFilter-chrome-v${VER}.zip"
export CSS=`./compile.pl $PARAMS --flag=CHROME settings.css`
export HTML=`./compile.pl $PARAMS --flag=CHROME settings.html`
rm -f release/latest/chrome/*
cp chrome/* release/latest/chrome/
./compile.pl --nocompress -out="release/latest/chrome/manifest.json" chrome/manifest.json
./compile.pl $COMPRESS $PARAMS --out="release/latest/chrome/main.js" chrome/main.js
./compile.pl $COMPRESS $PARAMS --flag=CHROME --out="release/latest/chrome/weiboFilter.js" weiboFilter.user.js
zip -q -j $PACKAGE release/latest/chrome/*
echo ' done.'

unset VER MAINVER REV